// pages/sita/test/test.js
const CONTEXT = require('../../../utils/public_var')
const GOODS = require("../../fun_js/goods.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalCount:10,
    hideTip:false,
    imgPath:'',
    bar_type:CONTEXT.TEXT_PAGE_TYPE,
    PAGETYPE:CONTEXT.IMG_PAGE_TYPE,
    funcSupport:{
      "textInput": {
          "available":"1",
          "iconAddr":"https://genious.sitacloud.com/icon_imagee/textInput.svg",
          "iconName":"主公，请吩咐"
      },
      "imageOCR": {
        "available":"1",
        "iconAddr":"https://genious.sitacloud.com/icon_imagee/imageOCR.svg",
        "iconName":"文字识别"
      },
      "voiceInput":{
        "available":"1"
      },
      "fileupload": {
        "available":"0"
      },
      "soundupload": {
        "available":"1"
      },
      "imageupload": {
        "available":"1",
        "iconAddr":"https://genious.sitacloud.com/icon_imagee/imageupload.svg",
        "iconName":"图片处理"
      }
               }
      
 
 
  },


  saf(){
    wx.switchTab({
      url: '../prompts/prompts',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  send(){
    var that =this
    wx.chooseMedia({
      count: 1,
      sizeType: ['compressed'],
      mediaType: ['image'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        var imgs = res.tempFiles[0].tempFilePath;
        // console.log(imgs)
        that.upload(imgs)
      },
    })
  },
  upload(src){
    let requestBody = {
      'prompt': [{
        "role": 'user',
        "content": "帮我翻译哦",
        "msgtype":CONTEXT.TEXT
        },
        {
          "role": 'user',
          "content": "I love kotlin",
          "msgtype":CONTEXT.TEXT
          }
    ],
    'openid': app.globalData.OpenID
    }
    let jsonData = JSON.stringify(requestBody)
    wx.uploadFile({
      url: "https://genious.sitacloud.com/v2question_search",
      filePath: src,
      name: 'mediafile',
      formData: {
        'chatStringBody':jsonData
    },
      timeout:60000,
      success: (res) => {
        wx.hideLoading();
        console.log(res);
       
      },
      fail: (res) => {
        wx.hideLoading();
        console.log(res);
      },
    });
  }
})